JobView = Ext.extend(Ext.Panel, {
	constructor : function(a) {
		Ext.applyIf(this, a);
		this.initUIComponents();
		JobView.superclass.constructor.call(this, {
			id : "JobView",
			title : "职位人员管理",
			region : "center",
			layout : "border",
			border : false,
			iconCls : "menu-job",
			items : [ this.gridPanel, this.searchPanel, this.jobTreePanel ]
		});
	},
	initUIComponents : function() {
		this.topbar = new Ext.Toolbar({
			defaultType : "button",
			items : [
					{
						text : "添加",
						iconCls : "add-user",
						scope : this,
						handler : function() {
							var f = Ext.getCmp("jobViewJobTreePanel")
									.getSelectionModel().getSelectedNode();
							if (f != null && f.id > 0) {
								new UserJobForm({
									jobId : f.id,
									jobName : f.text
								}).show();
							} else {
								new UserJobForm({}).show();
							}
						}
					}, "-", {
						text : "删除",
						iconCls : "btn-del",
						scope : this,
						handler : this.removeByIds
					} ]
		});
		this.searchPanel = new Ext.FormPanel({
			id : "JobViewSearchPanel",
			region : "north",
			layout : "hbox",
			border : false,
			height : 40,
			frame : false,
			keys : {
				key : Ext.EventObject.ENTER,
				scope : this,
				fn : this.search
			},
			layoutConfig : {
				padding : "5px",
				align : "middle"
			},
			defaults : {
				xtype : "label",
				border : false,
				margins : {
					top : 0,
					left : 5,
					right : 5,
					bottom : 0
				}
			},
			items : [ {
				text : "用户账号："
			}, {
				xtype : "textfield",
				name : "Q_appUser.username_S_LK",
				maxLength : 256
			}, {
				text : "用户名称："
			}, {
				xtype : "textfield",
				name : "Q_appUser.fullname_S_LK",
				maxLength : 256
			}, {
				text : "主职位(是/否)："
			}, {
				xtype : "combo",
				hiddenName : "Q_isMain_SN_EQ",
				mode : "local",
				triggerAction : "all",
				editable : false,
				store : [ [ "0", "否" ], [ "1", "是" ] ],
				emptyText : "全部"
			}, {
				xtype : "button",
				text : "搜索",
				iconCls : "search",
				scope : this,
				handler : this.search
			}, {
				xtype : "button",
				text : "清空",
				iconCls : "reset",
				scope : this,
				handler : this.reset
			} ]
		});
		this.gridPanel = new HT.GridPanel({
			id : "jobUserGrid",
			title : "职位人员列表",
			region : "center",
			tbar : this.topbar,
			rowActions : true,
			url : __ctxPath + "/system/listUserJob.do",
			trackMouseOver : true,
			disableSelection : false,
			loadMask : true,
			viewConfig : {
				forceFit : true,
				enableRowBody : false,
				showPreview : false
			},
			fields : [ {
				name : "userJobId",
				type : "int"
			}, "job", "appUser", "isMain" ],
			columns : [ {
				header : "userJobId",
				dataIndex : "userJobId",
				hidden : true
			}, {
				header : "员工账号",
				dataIndex : "appUser",
				renderer : function(f) {
					return f.userId;
				}
			}, {
				header : "员工名称",
				dataIndex : "appUser",
				renderer : function(f) {
					return f.username;
				}
			}, {
				header : "职位",
				dataIndex : "job",
				renderer : function(f) {
					return f.jobName;
				}
			}, {
				header : "主职位(是/否)",
				dataIndex : "isMain",
				renderer : function(f) {
					return f == 1 ? "是" : "否";
				}
			}, new Ext.ux.grid.RowActions({
				header : "管理",
				width : 100,
				actions : [ {
					iconCls : "btn-del",
					qtip : "删除",
					style : "margin : 0 3px 0 3px"
				}, {
					iconCls : "btn-edit",
					qtip : "编辑",
					style : "margin : 0 3px 0 3px"
				}, {
					iconCls : "btn-showDetail",
					qtip : "查看职位信息",
					style : "margin : 0 3px 0 3px"
				} ],
				listeners : {
					scope : this,
					"action" : this.onRowActions
				}
			}) ]
		});
		this.gridPanel.addListener("rowdblclick", function(f, h, g) {
			f.getSelectionModel().each(function(i) {
				new UserJobForm({
					userJobId : i.data.userJobId,
					jobName : i.data.job.jobName
				}).show();
			});
		});
		this.jobTreePanel = new Ext.tree.TreePanel({
			id : "jobViewJobTreePanel",
			region : "west",
			border : false,
			width : 200,
			collapsible : false,
			autoScroll : true,
			split : true,
			title : "职位信息列表",
			tbar : new Ext.Toolbar({
				defaultType : "button",
				items : [ {
					text : "刷新",
					iconCls : "btn-refresh",
					handler : function() {
						Ext.getCmp("jobViewJobTreePanel").root.reload();
					}
				}, {
					text : "展开",
					iconCls : "btn-expand",
					handler : function() {
						Ext.getCmp("jobViewJobTreePanel").expandAll();
					}
				}, {
					text : "收起",
					iconCls : "btn-collapse",
					handler : function() {
						Ext.getCmp("jobViewJobTreePanel").collapseAll();
					}
				} ]
			}),
			loader : new Ext.tree.TreeLoader({
				url : __ctxPath + "/hrm/treeLoadJob.do"
			}),
			root : new Ext.tree.AsyncTreeNode({
				expanded : true
			}),
			rootVisible : false,
			listeners : {
				"click" : this.clickNode
			}
		});
		this.jobTreePanel.on("contextmenu", b, this.jobTreePanel);
		var c = new Ext.menu.Menu({
			id : "jobTreeMenu",
			items : [ {
				text : "新增职位信息",
				iconCls : "btn-add",
				scope : this,
				handler : e
			}, {
				text : "修改职位信息",
				iconCls : "btn-edit",
				scope : this,
				handler : a
			}, {
				text : "删除职位信息",
				iconCls : "btn-del",
				scope : this,
				handler : d
			} ]
		});
		function b(f, g) {
			jobSelected = new Ext.tree.TreeNode({
				id : f.id,
				text : f.text
			});
			c.showAt(g.getXY());
		}
		function e() {
			var f = jobSelected.id;
			if (f > 0) {
				new JobForm({
					parentId : f
				}).show();
			} else {
				new JobForm({
					parentId : 0
				}).show();
			}
		}
		function a() {
			var f = jobSelected.id;
			if (f > 0) {
				new JobForm({
					jobId : f
				}).show();
			} else {
				Ext.ux.Toast.msg("操作提示", "对不起，公司名称不能修改！");
			}
		}
		function d() {
			var f = jobSelected.id;
			if (f > 0) {
				Ext.Msg.confirm("操作提示", "你真的要删除该职位信息吗？", function(g) {
					if (g == "yes") {
						var h = Ext.getCmp("jobViewJobTreePanel");
						Ext.Ajax.request({
							url : __ctxPath + "/hrm/deleteJob.do?jobId=" + f,
							method : "post",
							waitMsg : "数据正在提交，请稍后...",
							success : function(i, k) {
								var j = Ext.util.JSON.decode(i.responseText);
								if (j.success) {
									Ext.ux.Toast.msg("操作提示", "删除该职位信息操作成功！");
									h.root.reload();
								} else {
									Ext.ux.Toast
											.msg("操作提示", "对不起，删除该职位信息操作失败！");
								}
							}
						});
					}
				});
			} else {
				Ext.ux.Toast.msg("操作提示", "对不起，公司名称不能删除！");
			}
		}
	},
	onRowActions : function(c, a, d, e, b) {
		switch (d) {
		case "btn-showDetail":
			this.showDetail.call(this, a);
			break;
		case "btn-edit":
			this.editById.call(this, a);
			break;
		case "btn-del":
			this.removeById.call(this, a.data.userJobId);
			break;
		default:
			break;
		}
	},
	reset : function() {
		var a = Ext.getCmp("JobViewSearchPanel");
		a.getForm().reset();
	},
	search : function() {
		var g = Ext.getCmp("JobViewSearchPanel");
		var c = g.getCmpByName("Q_appUser.username_S_LK").getValue();
		var h = g.getCmpByName("Q_appUser.fullname_S_LK").getValue();
		var b = g.getCmpByName("Q_isMain_SN_EQ").getValue();
		var e = Ext.getCmp("jobUserGrid");
		var a = Ext.getCmp("jobViewJobTreePanel");
		var f = a.getSelectionModel().getSelectedNode();
		var d = e.getStore();
		if (f != null && f.id > 0) {
			d.baseParams = {
				"Q_job.jobId_L_EQ" : f.id,
				"Q_appUser.username_S_LK" : c,
				"Q_appUser.fullname_S_LK" : h,
				"Q_isMain_SN_LK" : b
			};
		} else {
			d.baseParams = {
				"Q_appUser.username_S_LK" : c,
				"Q_appUser.fullname_S_LK" : h,
				"Q_isMain_SN_EQ" : b
			};
		}
		if (g.getForm().isValid()) {
			d.reload({
				params : {
					start : 0,
					limit : 25
				}
			});
		}
	},
	editById : function(a) {
		new UserJobForm({
			userJobId : a.data.userJobId,
			jobName : a.data.job.jobName
		}).show();
	},
	showDetail : function(a) {
		var b = a.data.appUser;
		UserJobDetailForm.show(b.userId, b.username);
	},
	removeById : function(a) {
		Ext.Msg.confirm("操作提示", "你真的要删除所选数据吗？", function(b) {
			if (b == "yes") {
				Ext.Ajax.request({
					url : __ctxPath + "/system/multiDelUserJob.do",
					params : {
						ids : a
					},
					method : "post",
					waitMsg : "数据正在提交，请稍后...",
					success : function(c, d) {
						Ext.ux.Toast.msg("操作提示", "数据删除成功！");
						Ext.getCmp("jobUserGrid").getStore().reload();
					},
					failure : function() {
						Ext.ux.Toast.msg("操作提示", "对不起，数据提交失败！");
					}
				});
			}
		});
	},
	removeByIds : function() {
		var d = Ext.getCmp("jobUserGrid");
		var a = d.getSelectionModel().getSelections();
		if (a.length > 0) {
			var c = new Array();
			for (var b = 0; b < a.length; b++) {
				c.push(a[b].data.userJobId);
			}
			this.removeById(c);
		} else {
			Ext.ux.Toast.msg("操作提示", "对不起，请选择要删除的员工信息！");
		}
	},
	clickNode : function(e) {
		if (e != null) {
			var d = Ext.getCmp("JobViewSearchPanel");
			var b = d.getCmpByName("Q_appUser.username_S_LK").getValue();
			var f = d.getCmpByName("Q_appUser.fullname_S_LK").getValue();
			var a = d.getCmpByName("Q_isMain_SN_EQ").getValue();
			var c = Ext.getCmp("jobUserGrid").getStore();
			if (e != null && e.id > 0) {
				c.baseParams = {
					"Q_job.jobId_L_EQ" : e.id,
					"Q_appUser.username_S_LK" : b,
					"Q_appUser.fullname_S_LK" : f,
					"Q_isMain_SN_EQ" : a
				};
			} else {
				c.baseParams = {
					"Q_appUser.username_S_LK" : b,
					"Q_appUser.fullname_S_LK" : f,
					"Q_isMain_SN_EQ" : a
				};
			}
			c.reload({
				params : {
					start : 0,
					limit : 25
				}
			});
		}
	}
});